package com.kitten.note.biz.consumer;


import com.kitten.note.biz.constants.MQConstants;
import com.kitten.note.biz.service.NoteService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

// Listener的三个参数：
// consumerGroup：消费者组，用来区分不同的消费者，同一组的消费者可以共同消费同一个topic的消息。
// topic：消息的主题，可以是一个或者多个。
// messageModel：消息的模式，可以是集群消费，广播消费，或者是单播消费。
@Component
@Slf4j
@RocketMQMessageListener(consumerGroup = "kittenBook_group_" + MQConstants.TOPIC_DELETE_NOTE_LOCAL_CACHE ,
        topic = MQConstants.TOPIC_DELETE_NOTE_LOCAL_CACHE,messageModel = MessageModel.BROADCASTING)
public class DeleteNoteLocalCacheConsumer implements RocketMQListener<String> {
    @Resource
    private NoteService noteService;

    @Override
    public void onMessage(String body) {
        Long noteId = Long.valueOf(body);
        noteService.deleteNoteLocalCache(noteId);
        log.info("Received message: " + body);
    }

}
